// pages/ky/ky.js

const HttpUtils = require('../../utils/HttpUtils')
const http = require('../../utils/HttpUtils')
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    Sxxz:[
      {
        id: "1",
        menuName: "开原概况",
        sort: 1,
        state: "1",
        url: './img/1111.jpg',
      },
      {
        id: "2",
        menuName: "开发区",
        sort: 2,
        state: "1",
        url: "./img/2222.jpg",
      },
      {
        id: "3",
        menuName: "开原商城",
        sort: 3,
        state: "1",
        url: "./img/3333.jpg",
      },
      {
        id: "4",
        menuName: "招商推荐",
        sort: 4,
        state: "1",
        url: "./img/4444.jpg",
      },
    ],
    menu:'',
    interval: 0,
    shareImg: '',
    shareTitle: '',
    isfirst: false,
    index: '1',
    click: 1,
    list: [],
    carouselImgUrls: [],
    listaddress1: [],
    listaddress: [],
    Dtpage:1,
    Ygpage:1,
    dtend:false,
    ygend:false,
    topNum:0,
  },

  // HttpUtils.URL_MENU
  // getMenu

  getMenu(){
    let that= this
    wx.request({
      url: HttpUtils.URL_MENU,
      method:'POST',
      success:function(res){
        that.setData({
          menu:res.data.menu
        })
      }
    })
  },

  getsxxz(){
    wx.request({
      url: HttpUtils.URL_Sxxz,
      method:'GET',
      success:(res)=>{
        this.setData({
          Sxxz:res.data.data,
        })
        console.log(this.data.Sxxz)
      }
    })
  },

  getTab(){
    wx.request({
      url: HttpUtils.URL_TAB,
      method:'POST',
      success:(res)=>{
        console.log(res)
        wx.setTabBarItem({
          index: 0,
          text: res.data.menu.name1,
        })
        wx.setTabBarItem({
          index: 1,
          text: res.data.menu.name2,
        })
        wx.setTabBarItem({
          index: 2,
          text: '招商政策',
        })
        wx.setTabBarItem({
          index: 3,
          text: res.data.menu.name3,
        }) 
        wx.setTabBarItem({
          index: 4,
          text: res.data.menu.name4,
        })
      }
    })
  },

  close() {
    app.globalData.isfirst = false
    this.setData({
      isfirst: false
    })
    wx.showTabBar()
  },

  getDtlist() {
    let that = this
    wx.request({
      url: http.URL_KFQDT + '?openId=' + app.globalData.openId +'&page='+this.data.Dtpage +'&limit=6',
      method: 'POST',
      success: (res) => {
        if(res.data.page.list!=''){
          var list = that.data.listaddress.concat(res.data.page.list)
        }else{
          that.setData({
            dtend:true
          })
        }
        that.setData({
          listaddress: list
        })
      }
    })
  },

  getMore(){
    if(this.data.click==1&&this.data.dtend==false){
      this.setData({
        Dtpage:this.data.Dtpage +1
      })
      this.getDtlist()
    }else if(this.data.click==2&&this.data.ygend==false){
      this.setData({
        Ygpage:this.data.Ygpage +1
      })
      this.getYGlist()
    }
  },

  getYGlist() {
    let that = this
    wx.request({
      url: http.URL_YGXQ + '?openId=' + app.globalData.openId+'&page='+this.data.Ygpage +'&limit=6',
      method: 'POST',
      success: (res) => {
        // console.log(res,'URL_YGXQ');
        if(res.data.page.list!=''){
          var list = that.data.listaddress1.concat(res.data.page.list)
        }else{
          that.setData({
           ygend:true
          })
        }
        that.setData({
          listaddress1: list
        })
      }
    })
  },

  look(e) {
    wx.previewImage({
      current: 'https://zs.lslnii.com/file/chainImg/kylogo.png',
      urls: ['https://zs.lslnii.com/file/chainImg/kylogo.png']
    })
  },

  zhaoshang() {
    this.setData({
      click: 1,
      topNum:0
    })
  },
  
  more() {
    this.setData({
      click: 2,
      topNum:0
    })
  },

  overview(e) {
    let a = e.currentTarget.dataset.index
    if(a==0){
      wx.navigateTo({
        url:'/pages/overView/overView',
      })
    }
    if(a==1){
      wx.navigateTo({
        url: '/pages/kfq/kfq',
      })
    }
    if(a==2){
      wx.navigateTo({
        url: '/Mall/pages/vides/vides',
      })
    }
    if(a==3){
      wx.navigateTo({
        url: '/pages/industrialChain/industtrialChain',
      })
    }
  },

  map() {
    wx.switchTab({
      url: '/pages/inMap/inMap',
    })
  },

  chan() {
    wx.switchTab({
      url: '/pages/industrialChain/industtrialChain',
    })
  },

  investment() {
    wx.navigateTo({
      url: '/pages/Idle/Idle',
    })
  },

  pagess() {
    wx.navigateTo({
      url: '/pages/kyBasicInformation/kyBasicInformation',
    })
  },

  toDetail(e) {
    var content = e.currentTarget.dataset.content
    var click = this.data.click

    wx.navigateTo({
      url: '/pages/info/info?content=' + encodeURIComponent(content)+'&id=1',
    })
  },

  getLunbo() {
    let that = this
    wx.request({
      url: http.URL_LUNBO + '?openId=' + app.globalData.openId,
      method: 'POST',
      success: (res) => {

        that.setData({
          interval: res.data.data[0].showTime * 1000,
          list: res.data.data
        })
      }
    })
  },

  getUser() {
    let that = this
    wx.request({
      url: http.URL_Info + '?openId=' + app.globalData.openId,
      method: 'POST',
      success: (res) => {
        console.log(res, 'userinfo')
        if (res.data.data == '') {
          wx.showModal({
            title: '提示',
            content: '您还没有注册，点击确定按钮成为会员',
            success(res) {
              if (res.confirm) {
                wx.reLaunch({
                  url: '../register/register',
                })
              } else if (res.cancel) {
                console.log('用户点击取消')
              }
            }
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // 胶囊按钮位置信息
    const menuButtonInfo = wx.getMenuButtonBoundingClientRect();
    this.setData({
      navBarHeight: menuButtonInfo.bottom,
    })
    // this.getUser()
    this.getLunbo()
    this.getDtlist()
    this.getYGlist()
    this.getMenu()
    // this.getsxxz()
    this.getTab()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    // 
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    return app.globalData.globalShareInfo
  }
})